﻿@model ProductModel.ProductVariantAttributeValueListModel

@using Telerik.Web.Mvc.UI;
@{    
    //page title
    ViewBag.Title = string.Format(T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.EditAttributeDetails").Text, Model.ProductVariantAttributeName, Model.ProductName);
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "productvariantattribute-form" }))
{
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" />
        @string.Format(T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.EditAttributeDetails").Text, Model.ProductVariantAttributeName, Model.ProductName)
        @Html.ActionLink("(" + T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.BackToProduct") + ")", "Edit", "Product", new { Id = Model.ProductId }, null)
    </div>
    <div class="options">
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<ProductModel.ProductVariantAttributeValueModel>()
                            .Name("pvav-grid")
                            .DataKeys(x =>
                            {
                                x.Add(y => y.Id).RouteKey("pvavId");
                                x.Add(y => y.ProductVariantAttributeId).RouteKey("productVariantAttributeId");
                            })
                            .Columns(columns =>
                            {
                                columns.Bound(x => x.AttributeValueTypeName);
                                columns.Bound(x => x.Name);
                                columns.Bound(x => x.AssociatedProductName);
                                //TODO display localized values here
                                columns.Bound(x => x.PriceAdjustmentStr)
                                    .Centered();
                                columns.Bound(x => x.WeightAdjustmentStr)
                                    .Centered();
                                columns.Bound(x => x.IsPreSelected)
                                    .Template(
                                        @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.IsPreSelected.ToString().ToLowerInvariant() + ".gif")" />
                                    )
                                    .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= IsPreSelected #>.gif' />")
                                    .Centered();
                                columns.Bound(x => x.PictureThumbnailUrl)
                                    .Centered()
                                    .ClientTemplate("<img  alt='' src='<#= PictureThumbnailUrl #>' />");
                                columns.Bound(x => x.DisplayOrder)
                                    .Centered();
                                columns.Bound(x => x.Id)
                                    .Width(50)
                                    .Centered()
                                    .ClientTemplate("<input type='submit' value='" + @T("Admin.Common.Edit").Text + "' onclick=\"" + "javascript:OpenWindow('" + @Url.Content("~/Admin/Product/ProductAttributeValueEditPopup/") + "<#= Id #>?btnId=btnRefresh&formId=productvariantattribute-form', 800, 500, true); return false;\" class='t-button' />")
                                    .Title(T("Admin.Common.Edit").Text);
                                columns.Command(commands =>
                                {
                                    commands.Delete().Text(T("Admin.Common.Delete").Text);
                                })
                                .Width(50)
                                .Title(T("Admin.Common.Delete").Text);
                            })
                            .DataBinding(dataBinding =>
                                dataBinding.Ajax()
                                .Select("ProductAttributeValueList", "Product", new { productVariantAttributeId = Model.ProductVariantAttributeId })
                                .Delete("ProductAttributeValueDelete", "Product"))
                            .EnableCustomBinding(true))
        </td>
    </tr>
    <tr>
        <td width="100%">
            <input type="submit" id="btnAddNewValue" name="btnAddNewValue" value="@T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("ProductAttributeValueCreatePopup", "Product", new { productAttributeAttributeId = Model.ProductVariantAttributeId, btnId = "btnRefresh", formId = "productvariantattribute-form" }))', 800, 500, true); return false;" class="t-button" />
            <input type="submit" id="btnRefresh" name="btnRefresh" style="display: none" />
            <script type="text/javascript">
                $(document).ready(function () {
                    $('#btnRefresh').click(function () {
                        //refresh grid
                        var optionsGrid = $("#pvav-grid");
                        optionsGrid.data('tGrid').ajaxRequest();

                        //return false to don't reload a page
                        return false;
                    });
                });
            </script>
        </td>
    </tr>
</table>
}